package com.jjsc.carousel.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jjsc.carousel.domain.Banner;
import com.jjsc.carousel.mapper.BannerMapper;
import com.jjsc.common.core.utils.StringUtils;
import com.jjsc.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 钟城明
 * @CreateTime: 2025-10-05
 * @Description:
 * @Version: 1.0
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements IBannerService {

    @Override
    public List<Banner> selectBannerList(Banner banner) {
        return this.list(new LambdaQueryWrapper<Banner>()
                .like(StringUtils.isNotBlank(banner.getTitle()),Banner::getTitle, banner.getTitle())
                .eq(StringUtils.isNotBlank(banner.getStatus()), Banner::getStatus, banner.getStatus())
                .eq(Banner::getDelFlag, "0")
                .orderByAsc(Banner::getSort)
        );
    }

    @Override
    public void updateSort(List<Banner> banners) {
        for (Banner banner : banners) {
            banner.setUpdateBy(SecurityUtils.getUsername());
            this.updateById(banner);
        }
    }
}
